<?php
///关于标收费信息的统计
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
$sfwhere      = "";
if($startdate!="" && $enddate!=""){
     
    $sfwheres    = " and time_l >='$startdate' and  time_l<='$enddate'"; 
    
} 
$gfileds        = "SUBSTR(time_l,1,10 )";
if($MOD=="M"){
    $gfileds    = "SUBSTR(time_l,1,7)";    
}

$sqln = "SELECT $gfileds '设置时间',sum(if(fuid_Auto_LastState(uid,concat(substr(time_l,1,10),' 23:59:59'))=1,1,0)) AS '开启',
count(uid) as 全部,sum(if(fuid_Auto_LastState(uid,concat(substr(time_l,1,10),' 23:59:59'))=-1,1,0)) AS '新增开启' 
FROM  05b_4uidauto  
WHERE 1 $sfwheres
GROUP BY $gfileds ";
//echo $sqln."\n\n";
$rows = $dbselect->GetRows($sqln);
foreach($rows as &$row)
{   
    $ctime      = $row['设置时间'];
    $count      = $row['开启'];
    $count_new  = $row['新增开启'];
    $count_all  = $row['全部'];
    CTLog::G()->pxxDayReal("sid",1,"自动_开启_全新",$count_new,$ctime);
    CTLog::G()->pxxDayReal("sid",1,"自动_开启_新增",$count,$ctime);
    CTLog::G()->pxxDayReal("sid",1,"自动_开启_全部",$count_all,$ctime);
}

$sqlc = "SELECT $gfileds '设置时间',sum(if(fuid_Auto_LastState(uid,concat(substr(time_l,1,10),' 23:59:59'))=0,1,0)) AS '关闭',
count(uid) as 全部
FROM  05b_4uidauto 
WHERE 1 $sfwheres
GROUP BY $gfileds ";
//echo $sqlc."\n";
$rows = $dbselect->GetRows($sqlc);
foreach($rows as &$row)
{   
    $ctime      = $row['设置时间'];
    $count      = $row['关闭'];
    $count_all  = $row['全部'];
    CTLog::G()->pxxDayReal("sid",1,"自动_关闭_新增",$count,$ctime);
    CTLog::G()->pxxDayReal("sid",1,"实名_关闭_全部",$count_all,$ctime);
}